/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */

package GestureRecognition;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments -
 */

public class Swipe {

    public Swipe() {
        try {
            robot = new Robot();

        } catch (AWTException ex) {
            Logger.getLogger(Swipe.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


     Robot robot;
    int framecount;
    int[] xdis = new int[15];
    int[] ydis = new int[15];
    int lasX;
    int lasY;
    int status = 0;
    boolean isNew = true;
    boolean started = false;

    public int velocity(int x) {
        if (x == 0) {
            if (lasX == 0) {
                status = 0;
                isNew = true;
                started = false;
            }
            return 0;
        } else {
            int dis=0;
            if (started) {
                dis = lasX - x;
            }
            started=true;
            lasX = x;
            xdis[status % 15] = dis;
            if (status == 14 && isNew) {
                isNew = false;
            }
            status = (status + 1) % 15;
            if (isNew) {
                return 0;
            } else {
                int h = 0;
                for (int f : xdis) {
                    h = h + f;
                }
                return h;
            }
        }
    }

    public void getVelocity(int x) {

        int velocity = velocity(x);
        //System.out.println(x);
       // System.out.println(velocity);
        if (velocity > 300) {
            status = 0;
            isNew = true;
            started=false;
            xdis = new int[15];
            robot.keyPress(KeyEvent.VK_RIGHT);

            System.out.println("right");
        } else if (velocity < -300) {
            status = 0;
            isNew = true;
            started=false;
            xdis = new int[15];
            robot.keyPress(KeyEvent.VK_LEFT);
            System.out.println("left");
        }
    }

}
